package ClonableDemo;
class Money implements Cloneable{
    public double money = 12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public String name;
    public Money m;

    public Person(String name) {
        this.name = name;
        m = new Money();
    }

//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.m =(Money) this.m.clone();
        return tmp;
    }
}
public class Test3 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person("张三");
        Person person2 = (Person) person1.clone();
        System.out.println("修改之前："+person1.m.money);
        System.out.println("修改之前："+person2.m.money);
        person2.m.money = 99.99;

        System.out.println("修改之后："+person1.m.money);
        System.out.println("修改之后："+person2.m.money);

    }

    public static void main1(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person("张三");
        Person person2 = (Person) person1.clone();

        System.out.println(person2.name);
    }
}
